<template>
    <el-container class="content">
        <el-header :height="'auto'">
            <breadcrumb :title="'车辆出入登记'" :noBack="true"></breadcrumb>
        </el-header>
        <el-main>
            <el-container class="white-block box full" v-loading="loading">
                <el-header :height="'auto'">
                    <div class="toolbar">
                        <div>
                            <el-input v-model="name" placeholder="请输入姓名或手机号" class="input short"
                                      size="small"></el-input>
                            <el-select v-model="action" placeholder="进/出" class="select short" size="small">
                                <el-option
                                    v-for="item in actionOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                            <el-select v-model="deptName" filterable placeholder="请选择科室" size="small" class="select"
                                       clearable>
                                <el-option
                                    v-for="item in deptList"
                                    :key="item.value"
                                    :label="item.name"
                                    :value="item.name">
                                </el-option>
                            </el-select>
                            <el-date-picker v-model="searchTime" size="small" class="short"
                                            type="daterange"
                                            range-separator="~"
                                            start-placeholder="开始日期"
                                            end-placeholder="结束日期">
                            </el-date-picker>
                            <el-button class="primary" @click="getList(1)" size="small">查询</el-button>
                            <el-button class="minor" @click="reset()" size="small">重置</el-button>
                            <el-button @click="dataExport()" size="small">导出</el-button>
                        </div>
                    </div>
                </el-header>
                <el-main class="mt10">
                    <table-example ref="table" :data="tableData" :tableColumn="header" :slotColumns="slotColumns"
                                   :stripe="true">
                        <template slot="action" slot-scope="scope">
                            <span v-if="scope.row.action==1">进</span>
                            <span v-else-if="scope.row.action==2">出</span>
                        </template>
                    </table-example>
                </el-main>
                <el-footer :height="'auto'" class="mt20">
                    <page :data="page" @jumpPage="getList"></page>
                </el-footer>
            </el-container>
        </el-main>
    </el-container>
</template>

<script>
    import tableExample from '../components/table'
    import page from '../components/pagination'
    import dialogMsk from '../components/dialog'
    import breadcrumb from '../components/breadcrumb'
    import qs from 'qs'

    export default {
        data() {
            return {
                name: '', // 姓名
                deptName: '', // 部门名称
                searchTime: '',
                actionOptions: [
                    {
                        label: '',
                        value: ''
                    },
                    {
                        label: '进',
                        value: 1
                    },
                    {
                        label: '出',
                        value: 2
                    }
                ],
                action: '', // 进/出
                tableData: [],
                header: [
                    {
                        prop: 'name',
                        label: '姓名',
                        minWidth: '100',
                        align: 'center'
                    },
                    {
                        prop: 'carIdNumber',
                        label: '车牌号',
                        minWidth: '100',
                        align: 'center'
                    },
                    {
                        prop: 'phone',
                        label: '联系方式',
                        minWidth: '120',
                        align: 'center'
                    },
                    {
                        prop: 'idCard',
                        label: '身份证号',
                        minWidth: '120',
                        align: 'center'
                    },
                    {
                        prop: 'visitDepartment',
                        label: '拜访科室',
                        minWidth: '150',
                        align: 'center'
                    },
                    {
                        prop: 'visitPeople',
                        label: '拜访人',
                        minWidth: '100',
                        align: 'center'
                    },
                    {
                        prop: 'action',
                        label: '进/出',
                        minWidth: '100',
                        align: 'center'
                    },
                    {
                        prop: 'createTime',
                        label: '登记时间',
                        minWidth: '150',
                        align: 'center'
                    }
                ],
                slotColumns: ['action'],
                page: {},
                index: 1,
                loading: false,
                deptList: []
            }
        },
        mounted() {
            let start = this.$filter.timeFormat(null, 'YYYY-MM-DD HH:mm:ss'),
                end = this.$filter.timeFormat(null, 'YYYY-MM-DD HH:mm:ss')
            this.searchTime = [start, end]
            this.getDept()
            this.getList()
        },
        methods: {
            getDept() {
                this.$http.get('/thisCourt/hsDepartmentData').then(result => {
                    if (result.success) {
                        this.deptList = result.data
                    }
                })
            },
            // 获取列表数据
            getList(index) {
                this.loading = true
                if (index) this.index = index
                this.$http.get('/vehicleRegistration/getCarCheckInInfo', {
                    startTime: this.searchTime && this.searchTime[0] ? this.$filter.timeFormat(this.searchTime[0], 'YYYY-MM-DD') : '', // 起始时间
                    endTime: this.searchTime && this.searchTime[1] ? this.$filter.timeFormat(this.searchTime[1], 'YYYY-MM-DD') : '', // 结束时间
                    nameOrPhone: this.name,
                    action: this.action,
                    visitDepartment: this.deptName,
                    current: this.index || 1,
                    size: 15
                }).then(result => {
                    this.loading = false
                    if (result.success) {
                        this.tableData = result.data.records
                        this.page = result.data
                        delete this.page['records']
                    }
                }).catch(() => {
                    this.loading = false
                })
            },
            // 重置操作
            reset() {
                let start = this.$filter.timeFormat(null, 'YYYY-MM-DD HH:mm:ss'),
                    end = this.$filter.timeFormat(null, 'YYYY-MM-DD HH:mm:ss')
                this.searchTime = [start, end]
                this.name = ''
                this.action = ''
                this.deptName = ''
                this.getList(1)
            },
            // Excel 导出
            dataExport() {
                let params = {
                    startTime: this.searchTime && this.searchTime[0] ? this.$filter.timeFormat(this.searchTime[0], 'YYYY-MM-DD') : '', // 起始时间
                    endTime: this.searchTime && this.searchTime[1] ? this.$filter.timeFormat(this.searchTime[1], 'YYYY-MM-DD') : '', // 结束时间
                    nameOrPhone: this.name,
                    action: this.action,
                    visitDepartment: this.deptName
                }, url = '/_api/vehicleRegistration/downCarCheckInInfo'
                url += '?' + qs.stringify(params)
                window.open(location.origin + url, '_blank')
            }
        },
        components: {
            tableExample,
            page,
            dialogMsk,
            breadcrumb
        }
    }
</script>

<style scoped lang="less">

</style>
